package la.iok.hzsvn.lewin.movie.operation.controller;

import la.iok.hzsvn.lewin.movie.core.Token;
import la.iok.hzsvn.lewin.movie.core.model.UuidParam;
import la.iok.hzsvn.lewin.movie.operation.model.MoviePlayerVo;
import la.iok.hzsvn.lewin.movie.operation.service.MoviePlayerService;
import la.iok.hzsvn.share.response.ListDataResponse;
import la.iok.hzsvn.share.response.OperatorResponse;
import la.iok.hzsvn.share.response.OperatorResponses;
import la.iok.hzsvn.share.response.SingleDataResponse;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("moviePlayers")
public class MoviePlayerController {
    private final MoviePlayerService moviePlayerService;

    public MoviePlayerController(MoviePlayerService moviePlayerService) {
        this.moviePlayerService = moviePlayerService;
    }

    @PostMapping
    public SingleDataResponse<Long> save(@RequestHeader Token token, @RequestBody UuidParam param){
        return new SingleDataResponse<>(moviePlayerService.save(token,param));
    }

    @GetMapping("r/{playRecordId}")
    public ListDataResponse<MoviePlayerVo> list(@RequestHeader Token token, @PathVariable Long playRecordId){
        return new ListDataResponse<>(moviePlayerService.players(token,playRecordId));
    }

    @GetMapping("{id}")
    public SingleDataResponse<MoviePlayerVo> mine(@RequestHeader Token token, @PathVariable Long id) {
        return new SingleDataResponse<>(moviePlayerService.mine(token,id));
    }

    @PutMapping("{id}/role/{playRoleId}")
    public OperatorResponse bindRole(@RequestHeader Token token,@PathVariable Long id, @PathVariable Long playRoleId) {
        moviePlayerService.bindRole(token,id,playRoleId);
        return OperatorResponses.success();
    }

    @PutMapping("{id}/role")
    public OperatorResponse clearRole(@RequestHeader Token token,@PathVariable Long id){
        moviePlayerService.clearRole(token,id);
        return OperatorResponses.success();
    }
    @DeleteMapping("{id}")
    public OperatorResponse removePlayer(@RequestHeader Token token,@PathVariable Long id){
        moviePlayerService.removeUser(token,id);
        return OperatorResponses.success();
    }
}
